<?php include show_tpl('public_uheader.htm'); ?>

<div style="width:100%; height:20px; background:#E9ECF3;"></div>

<?php include show_tpl('public_usider.htm'); ?>
<style>
	.modal .modal-dialog{
		top: 20px;
	}
</style>
<div id="page-wrapper" class="gray-bg">


<form method="get" class="form-inline m-b-xs" action="<?php echo url('user-channel');?>" style="height: 61px;padding-top: 14px">
	<div class="row">
		<div class="col-lg-2">
			<div class="form-group" style="width:100%;">
				<select name="type" class="form-control" style="width:100%;">
					<option value="0" <?php if($type==0){echo 'selected';} ?>>通道名称</option>
					<option value="1" <?php if($type==1){echo 'selected';} ?>>支付宝账号</option>
					<option value="2" <?php if($type==2){echo 'selected';} ?>>姓名</option>
				</select>
			</div>
		</div>		
		<div class="col-lg-3">
			<div class="form-group" style="width:100%;">
				<input type="text" class="form-control" name="keywords" placeholder="关键字" value="<?php echo $keywords;?>" size="15" style="width:100%;">
			</div>
		</div>
		<div class="col-lg-2">
			<button type="submit" class="btn btn-success" style="width:100%;">
				<i class="icon icon-search"></i>
				立即查询
			</button>
		</div>
		<div class="form-group">
			<a class="btn btn-primary active" href="user-gatewayadd.htm">添加通道</a>
		</div>
	</div>
</form>


	<div style="background: white" class="col-lg-12">
		<div class="card">
			<div class="table-responsive">
				<form action="<?php echo url('pay-channel');?>" method="POST">
					<table class="table table-bordered">
						<thead>
							<tr>
								<td class="text-center">名称</td>
								<!--<td class="text-center">网关名字</td>-->
								<td class="text-center">所属帐号</td>
								<td class="text-center">姓名</td>
								<td class="text-center">分类</td>
								<td class="text-center">单笔最大限额</td>
								<td class="text-center">每天最大金额</td>
								<td class="text-center">累计收款金额</td>
								<td class="text-center">状态</td>
								<td class="text-center">操作</td>
							</tr>
						</thead>
						<tbody>'
						<?php
						if(!empty($channel)){
						foreach($channel as $v){?>
							<tr style="<?php if($v['is_open']<1)echo 'background:#FFD0D0'?>">
								<td class="text-center"><?php echo $v['shortname']?></td>
								<!--<td class="text-center"><?php echo $v['gname']?></td>-->
								<td class="text-center"><?php echo $v['username']?></td>
								<td class="text-center"><?php echo $v['alipay_realname']?></td>
								<td class="text-center"><?php echo $v['catename']?></td>
								<td class="text-center"><?php echo $v['max_limit']?></td>
								<td class="text-center"><?php echo $v['max_price']?></td>
								<td class="text-center"><?php echo $v['money_total']?></td>
								<td class="text-center">
									<select data-id="<?php echo $v['id'];?>" class="form-control text-center open_this" name="is_open[<?php echo $v['id'];?>]">
									<option class="text-center" value="1" <?php if($v['is_open']==1){echo 'selected';} ?>>开</option>
									<option class="text-center" value="0" <?php if($v['is_open']==0){echo 'selected';} ?>>关</option>
								</select>
									<?php
									if($v['is_open']==0){
										switch ($v['close_reason']) {
											case 0:
												echo '手动关闭';
												break;
											case 1:
												echo '转账失败';
												break;
											case 2:
												echo '订单失败超限';
												break;
										}
									}
									?></td>
								<td>
									<a class="btn btn-danger del_chan" data-id="<?php echo $v['id'];?>" style="color: white">删除</a>
									<a href="<?php echo url("user-gatewayup-$v[id]");?>" style="color: white;margin-left: 5px" class="btn btn-primary">修改</a>
									<a class="btn btn-info see_all" style="color: white;margin-left: 5px" data-id="<?php echo $v['id'];?>">查看详情</a>
								</td>
							</tr>

						<?php }
						}
						?>
						</tbody>
					</table>
					<?php
					if(!empty($channel)){
					foreach($channel as $v){?>
					<div class="modal fade show_<?php echo $v['id']?>" tabindex="-1" role="dialog">
						<div class="modal-dialog" role="document">
							<div class="modal-content">
								<div class="modal-header">
									<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true" class="guan">&times;</span></button>
									<h4 class="modal-title">通道详情</h4>
								</div>
								<div class="modal-body">
									<p>网关信息</p>
									<div class="show_li">
										<div class="show_li_li1">简称</div>
										<div class="show_li_li"><?php echo $v['shortname']?></div>
										<div class="clear_both"></div>
									</div>
									<div class="show_li">
										<div class="show_li_li1">名称</div>
										<div class="show_li_li"><?php echo $v['gname']?></div>
										<div class="clear_both"></div>
									</div>
									<div class="show_li">
										<div class="show_li_li1">appid</div>
										<div class="show_li_li"><?php echo $v['api_id']?></div>
										<div class="clear_both"></div>
									</div>
									<div class="show_li">
										<div class="show_li_li1">密钥</div>
										<div class="show_li_li"><input class="form-control" value="<?php echo $v['api_secret']?>"></div>
										<div class="clear_both"></div>
									</div>
									<div class="show_li">
										<div class="show_li_li1">公钥</div>
										<div class="show_li_li"><input class="form-control" value="<?php echo $v['api_publickey']?>"></div>
										<div class="clear_both"></div>
									</div>
									<div class="show_li">
										<div class="show_li_li1">地址</div>
										<div class="show_li_li"><?php echo $v['url']?></div>
										<div class="clear_both"></div>
									</div>
									<p>通道信息</p>

									<div class="show_li">
										<div class="show_li_li1">支付宝</div>
										<div class="show_li_li"><?php echo $v['alipay_account']?></div>
										<div class="clear_both"></div>
									</div>
									<div class="show_li">
										<div class="show_li_li1">姓名</div>
										<div class="show_li_li"><?php echo $v['alipay_realname']?></div>
										<div class="clear_both"></div>
									</div>
									<div class="show_li">
										<div class="show_li_li1">所属用户</div>
										<div class="show_li_li"><?php echo $v['username']?></div>
										<div class="clear_both"></div>
									</div>
									<div class="show_li">
										<div class="show_li_li1">单笔最大限额</div>
										<div class="show_li_li"><?php echo $v['max_limit']?></div>
										<div class="clear_both"></div>
									</div>
									<div class="show_li">
										<div class="show_li_li1">每日最大金额</div>
										<div class="show_li_li"><?php echo $v['max_price']?></div>
										<div class="clear_both"></div>
									</div>
									<div class="show_li">
										<div class="show_li_li1">分类</div>
										<div class="show_li_li"><?php echo $v['catename']?></div>
										<div class="clear_both"></div>
									</div>
									<div class="show_li">
										<div class="show_li_li1">HOST</div>
										<div class="show_li_li"><?php echo $v['host']?></div>
										<div class="clear_both"></div>
									</div>
									<div class="show_li" style="border: none">
										<div class="show_li_li1">状态</div>
										<div class="show_li_li"><?php echo $v['is_open']?'开':"关";?></div>
										<div class="clear_both"></div>
									</div>
								</div>
								<div class="modal-footer">
									<button type="button" class="btn btn-default guan" data-dismiss="modal">关闭</button>
								</div>
							</div><!-- /.modal-content -->
						</div><!-- /.modal-dialog -->
					</div>
					<?php
					 }
					 }?>

				</form>
			</div>
			<hr class="m-t-0" />
		</div>
		<nav class="text-center"><ul class="pagination"><?php echo $pagination; ?></ul></nav>
	</div>

<div class="zhe" style="position: fixed;z-index: 13;background: black;top: 0;left:0;display: none;width: 120%;height: 100%;opacity: 0.3"></div>
<div class="modal fade" id="delcfmModel">
	<div class="modal-dialog">
		<div class="modal-content message_align">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
				<h4 class="modal-title">提示信息</h4>
			</div>
			<div class="modal-body">
				<p style="width: 100%;text-align: center;line-height: 30px">您确认要删除吗？</p>
				<?php   if($conf['is_open_sms']){?>
				<p>	<input id="smscode" type="text" style="width: 70%;float: left;" name="b_smscode" placeholder="请输入验证码" class="form-control" >
					<button class="btn btn-default" type="button" id="sendsms" data-phone="<?php echo $user['info_mobile']?>" style="width: 25%;margin-left: 5%;float: left;height: 34px;">获取验证码</button>
				<div style="clear:both;"></div>
				<?php }?>
				</p>
			</div>
			<div class="modal-footer">
				<input type="hidden" id="url"/>
				<button type="button" class="btn btn-default" data-dismiss="modal" style="color: #333333">取消</button>
				<a  onclick="urlSubmit()" class="btn btn-success" data-dismiss="modal" style="color: white">确定</a>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div>
</div>
<?php include show_tpl('public_ufooter.htm'); ?>


<script>
    var layer;
    var yzm;
    layui.use(['layer', 'form'], function(){
        layer = layui.layer
            ,form = layui.form;

    });
	var delid;
	$('.del_chan').click(function () {
        delid = $(this).attr('data-id');
	    delcfm()
    });
    function delcfm(url) {
        $('#delcfmModel').modal();
    }
    function urlSubmit(){
        <?php   if($conf['is_open_sms']){  ?>
        yzm = $('#smscode').val();
			if(yzm==undefined){
				layer.alert('验证码不能为空', {icon: 1});
			}
			<?php } ?>
        $.post("<?php echo url('user-delchannerl');?>", {id:delid,yzm:yzm}, function(data){
            layer.msg(data.data+'<i class="layui-icon layui-icon-face-smile" style="font-size: 30px; color: #1E9FFF;"></i> ');

            if(data.code==1) setTimeout(function(){window.location.reload()}, 700);
        });
    }
    $('.open_this').change(function () {
		var id = $(this).attr('data-id');
		var status = $(this).val();
        $.post("<?php echo url('user-upstatus');?>", {id:id,status:status}, function(data){
            layer.msg(data.data+'<i class="layui-icon layui-icon-face-smile" style="font-size: 30px; color: #1E9FFF;"></i> ');
            if(data.code==1) setTimeout(function(){window.location.reload()}, 700);
        });
    });
	var id;
	$('.see_all').click(function () {
		 id = $(this).attr('data-id');
		console.log(id)
		$('.show_'+id).removeClass('fade');
		$('.zhe').css('display','block');
        $('.show_'+id).css('display','block');
    });
	$('.guan').click(function () {
        $('.show_'+id).addClass('fade');
        $('.zhe').css('display','none');
        $('.show_'+id).css('display','none');
    })
var jform = $('form');
$('#submit').click(function(){
	var postdata = jform.serialize();
	$.post(jform.attr('action'), postdata, function(code, message){
        var data = $.parseJSON(code);
        if(data.code==1) setTimeout(function(){window.location.reload()}, 700);
	});
	return false;
});

var jconfirm = $("#confirm");
var juserlist = $('#userlist');
// 删除选中的记录
jconfirm.on('click', function(){
	var jchecked = juserlist.find('input[name="delete"]').filter(function(){ return this.checked; });
	if(jchecked.length < 1) return alert("请选择要删除的通道");
	if(!window.confirm("确认删除？")) return false;
	jchecked.each(function() {
		jtr = $(this).parents('tr');
		var uid = jtr.attr('uid');
		var passcode = $('#passcode').val();
		$.xpost(xn.url('pay-channeldel'), {id:uid,passcode:passcode}, function(code, message) {
			$.alert(message);
			if(code != 0) $('.tr'+uid).remove();
		});
	});
});
<?php    if($conf['is_open_sms']){ ?>
$('#nav_pc li.pay, #nav_mobile li.pay').tab('show');

    //发送验证码时添加cookie
    function addCookie(name,value,expiresHours){
//判断是否设置过期时间,0代表关闭浏览器时失效
        if(expiresHours>0){
            var date=new Date();
            date.setTime(date.getTime()+expiresHours*1000);
            $.cookie(name, escape(value), {expires: date});
        }else{
            $.cookie(name, escape(value));
        }
    }
    //修改cookie的值
    function editCookie(name,value,expiresHours){
        if(expiresHours>0){
            var date=new Date();
            date.setTime(date.getTime()+expiresHours*1000); //单位是毫秒
            $.cookie(name, escape(value), {expires: date});
        } else{
            $.cookie(name, escape(value));
        }
    }
    //根据名字获取cookie的值
    function getCookieValue(name){
        return $.cookie(name);
    }

    v = getCookieValue("secondsremained");//获取cookie值
    if(v>0){
        settime($("#sendsms"));//开始倒计时
    }
    var obj = $('#sendsms');
    $(function(){
        $('#sendsms').click(function () {
            var phone = $(this).attr('data-phone');
            var sta1 = isPhoneNum(phone);
            if(sta1){
//            console.log(phone)
                $.post("<?php echo url('user-sendSms')?>",{phone:phone},function (data) {
                    layer.alert(data.data, {icon: 1});
//                    yzm = data.smscode;
                    if(data.code==1){

                        addCookie("secondsremained",90,90);//添加cookie记录,有效时间60s
                        settime(obj);//开始倒计时

                    }else {

                    }

                })
            }

        })

    })



    //开始倒计时
    var countdown;
    function settime(obj) {
        countdown=getCookieValue("secondsremained");
        console.log(countdown)
        if (countdown == undefined) {
            obj.removeAttr("disabled");
            obj.html("获取验证码");
            return;
        } else {
            obj.attr("disabled", true);
            obj.html("重新发送需要(" + countdown + ")");
            countdown--;
            editCookie("secondsremained",countdown,countdown+1);
        }
        setTimeout(function() { settime(obj) },1000) //每1000毫秒执行一次
    }
    //校验手机号是否合法
    function isPhoneNum(phonenum){
        // var phonenum = $("#phonenum").val();
        var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
        if(!myreg.test(phonenum)){
            layer.alert('手机号不合法或者没有手机号', {icon: 1});
            return false;
        }else{
            return true;
        }
    }
<?php }?>
</script>